package com.itheima.demo01lambda;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author chenming
 * Date  2023/6/6 15:57
 * @version 1.0
 * description
 */
public class Demo03LambdaParam {
    public static void main(String[] args) {
        List<Person> persons = new ArrayList<>();
        persons.add(new Person("刘德华", 58, 174));
        persons.add(new Person("张学友", 58, 176));
        persons.add(new Person("刘德华", 54, 171));
        persons.add(new Person("黎明", 53, 178));

        Collections.sort(persons,(Person o1,Person o2)->{
            return o2.getAge() - o1.getAge(); //倒叙
        });

        System.out.println(persons.toString());
        persons.sort((o1, o2) -> o2.getHeight() - o1.getHeight());
        System.out.println(persons.toString());
        //下面该方法不好用
        persons = persons.stream().sorted(Comparator.comparing(Person::getAge)).collect(Collectors.toList());
        System.out.println(persons.toString());
        persons.sort(Comparator.comparing(Person::getAge).reversed()); //倒叙
        System.out.println(persons.toString());
    }

}
